//
//  ALPRecommendViewController.m
//  AlpFM
//
//  Created by KING on 16/1/25.
//  Copyright © 2016年 Alp. All rights reserved.
//

#import "ALPRecommendViewController.h"
#import "ALPFirstFloorModel.h"     //model
#import "ALPView.h" //头部
#import "ALPEditorCell.h"
#import "ALPListenListCellFirst.h"
#import "ALPHotRecommendsCell.h"
#import "ALPFiveCell.h"
#import "ALPEditorDetailVC.h"
#import "ALPEditorPlayVC.h"
#import "ALPListonListMoreVC.h"
#import "ALPAppTools.h"
#import "ALPListenListDetailsVC.h"
@interface ALPRecommendViewController ()<UITableViewDataSource,UITableViewDelegate,ALPEditorCellDelegate,ALPListenListCellFirstDelegate,ALPHotRecommendsCellDelegate>
@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic, strong) ALPFirstFloorModel *firsrModel;

@end

@implementation ALPRecommendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 512) style:UITableViewStylePlain];
    self.myTableView.dataSource = self;
    self.myTableView.delegate = self;
    self.myTableView.showsVerticalScrollIndicator = NO;
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;//取消滚动条
    self.myTableView.bounces = NO;
    
    [self.view addSubview:self.myTableView];
    

    [self getData];

    //注册
    [self.myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.myTableView registerClass:[ALPEditorCell class] forCellReuseIdentifier:@"cellEditor"];
    [self.myTableView registerClass:[ALPListenListCellFirst class] forCellReuseIdentifier:@"jingpin"];
    [self.myTableView registerClass:[ALPHotRecommendsCell class] forCellReuseIdentifier:@"hot"];
    [self.myTableView registerClass:[ALPFiveCell class] forCellReuseIdentifier:@"five"];

}
//每组间距
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}



//多少组
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}
//每组多少个cell
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
//每个cell高度   
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.section) {
        case 0:
            return 200;
            break;
        case 1:
            return 200;
            break;
        case 2:
            return 14 * 200 + 10 * 14;
            break;
        default:
            return 55;
            break;
    }
}

//cellforrow
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 0) {
        ALPEditorCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellEditor"];
        cell.xieyiren = self;
        cell.mol = self.firsrModel.editor;
        return cell;
    }else if(indexPath.section == 1){
        ALPListenListCellFirst *cell = [tableView dequeueReusableCellWithIdentifier:@"jingpin"];
        cell.xieyiren = self;
        cell.model = self.firsrModel.listenList;
        return cell;
    }else if(indexPath.section == 2){
        ALPHotRecommendsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"hot"];
        cell.xieyiren = self;
        cell.array = self.firsrModel.hot.list;
        return cell;
    }else{
        ALPFiveCell *cell = [tableView dequeueReusableCellWithIdentifier:@"five"];
        
        return cell;
    }
    
}


//点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
     [tableView deselectRowAtIndexPath:indexPath animated:NO];  //取消选中状态
    
    
}



//请求数据
-(void)getData{
    NSString *StrUrl = @"http://mobile.ximalaya.com/mobile/discovery/v1/recommends?channel=and-fix&device=android&includeActivity=true&includeSpecial=true&scale=2&version=4.3.38.2";
    [ALPAppTools getWithAFNurl:StrUrl block:^(id result) {
        self.firsrModel = [[ALPFirstFloorModel alloc]init];
        [self.firsrModel setValuesForKeysWithDictionary:result];
        [self.myTableView reloadData];
        // 放在头部
        ALPView *myView = [[ALPView alloc]initWithFrame:CGRectMake(0, 0, 375, 200)];
        myView.array = self.firsrModel.secondFocus.list;
        self.myTableView.tableHeaderView = myView;
    } error:^(NSError *error) {
        
        
    }];
}

//小编推荐点击更多跳转
-(void)jumpToDetail:(NSString *)title{
    ALPEditorDetailVC *detail = [[ALPEditorDetailVC alloc]init];
    detail.strTitle = title;
    [self.navigationController pushViewController:detail animated:YES];
}
//小编推荐正常点击
-(void)sendIndPath:(NSInteger)indPath idid:(NSInteger)idid jishu:(NSInteger)jishu{
    ALPEditorPlayVC *VC = [[ALPEditorPlayVC alloc]init];
    VC.indice = indPath;
    VC.idid = idid;
    VC.jishu = jishu;
    VC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:VC animated:YES completion:^{
        
    }];
}
//精品听单跳转更多
-(void)pushMoreVC:(NSString *)title{
    ALPListonListMoreVC *VC = [[ALPListonListMoreVC alloc]init];
    VC.strTitle = title;
    [self.navigationController pushViewController:VC animated:YES];
}

//点击听新闻
-(void)sengMessageidid:(NSInteger)idid indexPath:(NSInteger)indexPath jishu:(NSInteger)jishu{
    ALPEditorPlayVC *VC = [[ALPEditorPlayVC alloc]init];
    VC.indice = indexPath;
    VC.idid = idid;
    VC.jishu = jishu;
    VC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:VC animated:YES completion:^{
        
    }];
}
//精品听单点击cell
-(void)sendID:(NSInteger)ID contentType:(NSInteger)contentType{
    ALPListenListDetailsVC *VC = [[ALPListenListDetailsVC alloc]init];
    VC.specialId = ID;
    VC.contentType = contentType;
    [self.navigationController pushViewController:VC animated:YES];
  
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
